<template>
  <div class="m-user">
    <template v-if="user">
      欢迎您，
      <span class="username"> {{user}} </span>
      [
      <nuxt-link to="/exit">退出</nuxt-link>]
    </template>
    <template v-else>
      <nuxt-link to="/login" class="login">登录</nuxt-link>
      <nuxt-link to="register" class="register">注册</nuxt-link>
    </template>
  </div>
</template>
<script>
export default {
  name: "user",
  data() {
    return {
      user: ""
    };
  },
  mounted() {
    this.$axios.get("/users/getUser").then(({ status, data }) => {
      if (status === 200) {
        this.user = data.user;
      }
    });
  }
};
</script>
<style lang="scss">
</style>
